
import os

folder = "C:\\Users\\15871\\Pictures\\python-img"
counter = 1

# 打印某个文件夹下的所有文件名
for filename in os.listdir(folder):
    print(filename)
    if filename.endswith(".jpg"):
        new_filename = f"{counter:04d}.jpg" # 使用字符串格式化来生成新文件名
        # 重命名文件
        os.rename(os.path.join(folder, filename), os.path.join(folder, new_filename))
        counter += 1




